package com.wlyuan.open.scanner.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wlyuan.open.scanner.application.annotation.DataScope;
import com.wlyuan.open.scanner.dao.entity.FinanceBillDO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author yuanjie
 * @since 2022-12-26
 */
public interface FinanceBillMapper extends BaseMapper<FinanceBillDO> {

    @Select("select t.id,t.up,t.down,t.tenant_id as tenantId,t.create_time as createTime,t.update_time as updateTime from t_finance_bill t order by t.up asc " +
            "OFFSET ( #{pageNum} -1)* #{pageSize} ROWS FETCH next #{pageSize} rows only")
    @DataScope(column = "tenant_id", alias = "t")
    List<FinanceBillDO> list(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    @Select("select count(*) from t_finance_bill t ")
    @DataScope(column = "tenant_id", alias = "t")
    Integer count();

    @Select("select count(*) from t_finance_bill t where t.tenant_id = #{tenantId}")
    @DataScope(column = "tenant_id", alias = "t")
    Integer countByTenantId(@Param("tenantId") Long tenantId);

    @Select("select t.id,t.up,t.down,t.tenant_id as tenantId,t.create_time as createTime,t.update_time as updateTime from t_finance_bill t where t.tenant_id = #{tenantId} order by t.up asc  " +
            "OFFSET ( #{pageNum} -1)* #{pageSize} ROWS FETCH next #{pageSize} rows only")
    @DataScope(column = "tenant_id", alias = "t")
    List<FinanceBillDO> listByTenantId(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize, @Param("tenantId") Long tenantId);

    @Select("select top 1 t.id,t.up,t.down,t.tenant_id as tenantId,t.create_time as createTime,t.update_time as updateTime from t_finance_bill t where t.up = #{sourceId} or t.down = #{sourceId} ")
    @DataScope(column = "tenant_id", alias = "t")
    FinanceBillDO getByUpOrDown(Long sourceId);
}
